#include <string>
#include <vector>
#include <iostream>
#include "../cfa/cfa.h"
//#include "CFA_StructHandle.h"

bool IsStruct(Expr* e, map<Expr* , string> m_struct){
    bool result;
    map<Expr*, string>::iterator it;
    it=m_struct.find(e);
    if(it != m_struct.end()){
        result = false;
    }
    else{
        result = true;
    }
    return result;
}

bool IsType(string s_type, map<string, map<string, string> > m_type){
    bool result;
    map<string, map<string, string> >::iterator it;
    it = m_type.find(s_type);
    if(it != m_type.end()){
        result = false;
    }
    else{
        result = true;
    }
    return result;
}

string GetType(Expr* e, map<Expr*, string> m_struct){
    string s_type;
    map<Expr*, string>::iterator it;
    it=m_struct.find(e);
    if(it != m_struct.end()){
        s_type = "";
    }
    else{
        s_type = it->second;
    }
    return s_type;
}

map<string, string> GetMember(string s_type, map<string, map<string, string> > m_type){
    map<string, string> m_member;
    map<string, map<string, string> >::iterator it;
    it = m_type.find(s_type);
    if(it != m_type.end()){
        m_member.clear();
    }
    else{
        m_member = it->second;
    }
    return m_member;
}
void RecursiveGetMember(
map<string, map<string, string> > m,
map<string, map<string, string> >::iterator it_m,
vector<string> &result
){
    string s, sv;
    map<string, string>::iterator it_mm;
    for(it_mm = it_m->second.begin(); it_mm != it_m->second.end(); it_mm++){
        if(it_mm->second.compare("signedbv") == 0 || it_mm->second.compare("unsignedbv") == 0){
            result.push_back(it_mm->first);
        }
        else{
            vector<string> mv_s;
            map<string, map<string, string> >::iterator itm;
            for(itm = m.begin(); itm != m.end(); itm++){
                if(itm->first.compare(it_mm->second) == 0){
                    RecursiveGetMember(m, itm, mv_s);
                }
            }
            for(int i1 = 0; i1 < mv_s.size(); i1++){
                sv = it_mm->first + ".";
                sv = sv + mv_s[i1];
                result.push_back(sv);
            }
            //cout << "itmm first = " << it_mm->first << " second = " << it_mm->second << endl; 
        }
    }
}
